home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / trcopy.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  6KB  |  188 lines

  1. {$X+,B-,V-} {essential compiler directives}
  2.  
  3. Program TrCopy;
  4.  
  5. { Example for the nwConn unit/ NwTP 0.6 API. (c) 1993,1995, R. Spronk }
  6.  
  7. { Copies the time restrictions of a supplied user to amother user,
  8.   or another user group. The destination may conatain wildcards. }
  9.  
  10. { Note that it is possible to change the time restrictions of a number of
  11.   users by tagging them with F5 (in SYSCON) and then changing the time
  12.   restrictions. }
  13.  
  14. {(4395)  Tue 8 Feb 94  8:43
  15. By: Jos Cobbenhagen
  16. To: Allen
  17. Re: MUTATIE TIME-RESTR.
  18. St:
  19. ------------------------------------------------------------
  20. Aan     :Allen Van     :Jos Cobbenhagen Betreft :Mutaties Time-restrictions
  21.  
  22. Ik moet incidenteel voor een aantal wisselende afdelingen/gebruikers de
  23. time-restrictions aanpassen. Dit komt voor bij crises en apparte gebeurtenissen
  24. waarbij users ijdelijk 's avonds en in weekenden moeten werken. Enige
  25. mogelijkheid die ik hiervoor ken is voor de betreffende users appart deze
  26. restricties aanpassen, en voor 50+ gebruikers is dat vrij omslachtig. Vraag is
  27. of er een bindery utility is die dit in een keer voor een bepaalde groep
  28. gebruikers kan regelen?
  29. }
  30.  
  31. uses nwMisc,nwBindry;
  32.  
  33. Var source   :string;
  34.     TimeRestr:array[1..42] of byte;
  35.  
  36. Function ChangeTRforUser(dest:string):boolean;
  37. Var res:boolean;
  38.  
  39.     ObjName      :string;
  40.     ObjType      :word;
  41.     ObjId        :LongInt;
  42.     Iter         :LongInt;
  43.     Flag,Sec     :byte;
  44.     HasProperties:boolean;
  45.  
  46.     propValue:Tproperty;
  47.     moreSegs :boolean;
  48.     propFlags:byte;
  49. begin
  50. res :=false;
  51. iter:=-1;
  52. WHILE ScanBinderyObject(dest,OT_USER,iter,
  53.                         ObjName,ObjType,ObjId, Flag,Sec,HasProperties)
  54.  do begin
  55.     res:=true;
  56.     IF (source<>ObjName)
  57.        and ReadPropertyValue(ObjName,OT_USER,'LOGIN_CONTROL',1,
  58.                              propValue,moreSegs,propFlags)
  59.      then begin
  60.           Move(TimeRestr[1],propValue[15],42);
  61.           IF WritePropertyvalue(ObjName,ObjType,'LOGIN_CONTROL',1,
  62.                                 propValue,FALSE)
  63.             then writeln('Time restrictions of user ',ObjName,' changed.');
  64.           end;
  65.     end;
  66. ChangeTRForUser:=res;
  67. end;
  68.  
  69.  
  70. Function ChangeTRforGroup(GroupDest:string):boolean;
  71. Var res:boolean;
  72.  
  73.     ObjName      :string;
  74.     ObjType      :word;
  75.     ObjId        :LongInt;
  76.     Iter         :LongInt;
  77.     Flag,Sec     :byte;
  78.     HasProperties:boolean;
  79.  
  80.     propValue:Tproperty;
  81.     moreSegs :boolean;
  82.     propFlags:byte;
  83.     seg,i    :byte;
  84.  
  85.     UserObjId  :LongInt;
  86.     UserObjName:string;
  87. begin
  88. res :=false;
  89. iter:=-1;
  90. WHILE ScanBinderyObject(GroupDest,OT_USER_GROUP,iter,
  91.                         ObjName,ObjType,ObjId, Flag,Sec,HasProperties)
  92.  do begin
  93.     res:=true;
  94.     seg:=1;
  95.  
  96.     WHILE ReadPropertyValue(ObjName,OT_USER_GROUP,'GROUP_MEMBERS',seg,
  97.                             propValue,moreSegs,propFlags)
  98.       do begin
  99.          i:=1;
  100.          Repeat
  101.            UserObjId:=MakeLong((propValue[i]   *256 + PropValue[i+1] ),
  102.                                (propValue[i+2] *256 + PropValue[i+3] ) );
  103.            if UserObjId<>0
  104.             then begin
  105.                  IF GetBinderyObjectName(UserObjId,UserObjName,ObjType)
  106.                     and (UserObjName<>Source)
  107.                   then ChangeTRForUser(UserObjName);
  108.                  end;
  109.            inc(i,4);
  110.          Until (i>128) or (objId=0);
  111.  
  112.          inc(seg);
  113.          end;
  114.     end;
  115. ChangeTRForGroup:=res;
  116. end;
  117.  
  118. Procedure GetSourceTR(source:string);
  119. Var propValue:Tproperty;
  120.     MoreSegs :boolean;
  121.     PropFlags:byte;
  122. begin
  123. IF NOT ReadPropertyValue(source,OT_USER,'LOGIN_CONTROL',1,
  124.                          propValue,moreSegs,propFlags)
  125.     then begin
  126.          writeln;
  127.          Case nwBindry.result OF
  128.            $F0    :writeln('Wildcards in source not allowed.');
  129.            $FC,$FB:writeln('No such userobject');
  130.            $F9,$F1:writeln('Not enough privileges..');
  131.          else writeln('General error reading the bindery.');
  132.          end;{case}
  133.          Halt(1);
  134.          end;
  135. Move(propValue[15],TimeRestr[1],42);
  136. end;
  137.  
  138.  
  139. {--------------------------------- main -------------------------------------}
  140. Var dest    :string;
  141.     MyObjId :Longint;
  142.     secLevel:byte;
  143.     version :word;
  144.  
  145. begin
  146. If ParamCount<>2
  147.  then begin
  148.       writeln('----- TRCOPY: Copy Login Time Restrictions from one user to another. -----');
  149.       writeln;
  150.       writeln('Usage: TRCOPY <source> <dest>');
  151.       writeln;
  152.       writeln('Where <source> is the name of a USER,');
  153.       writeln('and <dest> the name of a user or group the time restrictions');
  154.       writeln('are to be copied to. <dest> may contain wildcards.');
  155.       writeln;
  156.       writeln('----- Use with NetWare 3.x only ---------- Written with the NwTP API -----');
  157.       halt(0);
  158.       end;
  159. writeln('TRCOPY: Copy Time Restrictions.');
  160. source:=ParamStr(1);
  161. dest  :=ParamStr(2);
  162. UpString(Source);
  163. UpString(dest);
  164.  
  165. IF (NOT GetBinderyAccessLevel(secLevel,MyObjId))
  166.    or (secLevel<>$33)
  167.  then begin
  168.       writeln;
  169.       writeln('You need to be logged in as a Supervisor equivalent user');
  170.       writeln('to use this utility.');
  171.       halt(1);
  172.       end;
  173.  
  174. GetNWversion(version);
  175. if (version DIV 100)<>3
  176.  then begin
  177.       writeln;
  178.       writeln('TRCOPY runs with NetWare 3.X only.');
  179.       halt(1);
  180.       end;
  181.  
  182. GetSourceTR(source);
  183.  
  184. IF NOT ChangeTRforUser(dest)
  185.  then IF NOT ChangeTRforGroup(dest)
  186.        then writeln('Error: destination user or group doesn''t exist.');
  187.  
  188. end.